function makeIESupportHTML5() {
	document.createElement('header');
	document.createElement('footer');
	document.createElement('section');
	document.createElement('aside');
	document.createElement('nav');
	document.createElement('article');
}

function ajax(url, method, data, callback) {
	var xhr = false;
	try {
		// For Old Microsoft Browsers
		xhr = new ActiveXObject('Msxml2.XMLHTTP');
	} catch (e) {
		try {
			// For Microsoft IE 6.0+
			xhr = new ActiveXObject('Microsoft.XMLHTTP');
		} catch (e2) {
			// No Browser accepts the XMLHTTP Object then false
			xhr = false;
		}
	}
	if (!xhr && typeof XMLHttpRequest != 'undefined') {
		// For Mozilla, Opera Browsers
		xhr = new XMLHttpRequest();
	}
	// Used to prevent caching during ajax call
	if (xhr) {
		xhr.onreadystatechange = function() {
			if (xhr.readyState == 4) {
				if (xhr.status == 200) {
					callback(xhr);
				} else {
					return;
				}
			}
		}
		xhr.open(method, url, true);
		// set this header to send POST
		xhr.setRequestHeader('Content-type',
				'application/x-www-form-urlencoded');
		xhr.send(data);
	}
}

function populateHome() {
	var section = "<section>";
	section += "<p class='meta'><img src='https://googledrive.com/host/0BwPdwaRwADWMM21jd3F6aDJobmM'/></p>";
	section += "<h1>How to keep it simple</h1>";
	section += "<p>One of the joys of keeping anything you do as simple as possible";
	section += "is making your achievement yours. Once you begin to make something,";
	section += "for example a website, you should learn from others. And you should";
	section += "get experience from many of course. Later your avarious thinkings";
	section += "will make your website become too more complex to control and";
	section += "remember all of its aspects. So at the begining, let keep it simple";
	section += "in mind, you shall not miss what are best while keeping control on";
	section += "what you are doing.</p>";
	section += "<p>Do you alway keep your things simple? And how do you keep them simple?";
	section += "Uhm, that is your work. Yuh, my work is on affecting your opinions";
	section += "about simplize. Hope my simple brain's topics do not take you much";
	section += "wasting time.</p>";
	section += "</section>";
	document.body.innerHTML += section;
	document.body.innerHTML += "<div id='posts-wrapper'></div>";
	ajax('http://inkisapi.appspot.com/simpleblog/posts', 'GET', null, function(xhr) {
		try {
			var jsonData = eval('(' + xhr.responseText + ')');
			var output = "";
			for (i=0; i<jsonData.results.length; i++){
				output += jsonData.results[i].content;
			}
			document.getElementById('posts-wrapper').innerHTML = output;
		} catch (e) {
			console.log(e);
		}
		appendFooter();
	});
}

function populateArchives() {
	document.body.innerHTML += "<div id='posts-wrapper'></div>";
	ajax('http://localhost:9999/simpleblog/posts', 'GET', null, function(xhr) {
		try {
			var jsonData = eval('(' + data + ')');
			var output = "";
			for (i=0; i<jsonData.results.length; i++){
				output += "<section>";
				output = "<p class='meta'>2013</p>";
				output += "<aside>" + jsonData.results[0].date + "</aside>";
				output += "<h1><a href='" + jsonData.results[0].id + "'>" 
						+ jsonData.results[0].tittle
						+ "</a></h1>";
				output += "</section>";
			}
			document.getElementById('posts-wrapper').innerHTML = output;
		} catch (e) {
			console.log(e);
		}
		appendFooter();
	});
}

function appendFooter() {
	var footer = "<footer><p class='meta'><img src='https://googledrive.com/host/0BwPdwaRwADWMRG5Kak5EVEw4OXM'/></p>";
	footer += "<p>KeepItSimple Project. In Development 2012. Author <a href='mailto:7inpham@gmail.com'>7inpham</a>.</p></footer>";
	document.body.innerHTML += footer;
}